import {BACKEND_BATH_URL} from "@/lib/constants";

export async function getNews() {
    try {
        const response =
            // 国内特色无法访问
            // await fetch('https://saurav.tech/NewsAPI/top-headlines/category/business/us.json');
            // json-server
            // await fetch(`${BACKEND_BATH_URL}/news/`);
            await fetch(`http://localhost:3000/forum/news.json`);

        if (!response.ok) {
            throw new Error('Network response was not ok');
        }
        const json = await response.text()
        // console.log(JSON.parse(news).us.technology.articles)

        // return json.us.business.articles
        return JSON.parse(json).us.technology.articles
    } catch (error) {
        console.error('Failed to fetch users:', error);
        return [];
    }
}
